package com.shelpe.services.sinbadgateway.client;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.sinbadgateway.client.CampaignClient.CampaignClientFallback;
import com.shelpe.services.sinbadgateway.entity.jpa.OnlineStatus;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@FeignClient(name="${feign.sinbadserver.name}", url="${feign.sinbadserver.url}", fallback = CampaignClientFallback.class)
public interface CampaignClient {
	
	@RequestMapping(method = RequestMethod.POST, path="/sinbadservice/campaigns",  consumes="application/json;charset=UTF-8")
	public CampaignDto createCampaign(@RequestBody CampaignDto dto);
	@RequestMapping(method = RequestMethod.PUT, path="/sinbadservice/campaigns/{campaign_id}",  consumes="application/json;charset=UTF-8")
	CampaignDto updateCampaign(@PathVariable("campaign_id")long campaignID, @RequestBody CampaignDto dto);
	
	@Data
	public static class CampaignDto {

		@JsonProperty("campaign_id")
		private long campaignID;
		
		@JsonProperty("user_id")
		private long userID;
		
		private int budget;

		private String title;
		private int autoType;
		
		private OnlineStatus onlineStatus;
	}
	
	@Service
	@Slf4j
	public static class CampaignClientFallback implements CampaignClient{

		@Override
		public CampaignDto createCampaign(CampaignDto dto) {
			log.error("fallback createCampaign: {}", dto);
			return new CampaignDto();
		}

		@Override
		public CampaignDto updateCampaign(long campaignID, CampaignDto dto) {
			log.error("fallback updateCampaign: {} {}", campaignID, dto);
			return new CampaignDto();
		}
		
	}
	
}
